package com.oneear.web;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.oneear.pojo.User;
import com.oneear.service.UserService;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.*;
import java.util.List;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@RequestMapping
@Controller
public class UserController {
    @Autowired

    private UserService userService;



    @GetMapping("pc/恋爱基地")
    public String toLiaijidi() {
        return "pc/恋爱基地";
    }

    @GetMapping("pc/恋爱基地内容页")
    public String toLiaijidiNei(Model model) {
        return "pc/恋爱基地内容页";
    }

    @GetMapping("pc/恋爱攻略")
    public String toLiaiGongLue( ) {
        return "pc/恋爱攻略";
    }
    @RequestMapping("pc/注册页面")
    public String toZhuCe() {
        System.out.println("返回注册页面");
       return "pc/注册页面";
    }

    @GetMapping("pc/首页")
    public String to(Long id, Model model) {
        User user = userService.queryById((long) 2);
        model.addAttribute("user", user);


        return "pc/首页";}
    @GetMapping("admin/会员列表")
    public String toHuiYuanList(){
        return "admin/会员列表";
    }
    @GetMapping("admin/信息通知")
    public String toXinXiTongZhi(){
        return "admin/信息通知";
    }
    @GetMapping("admin/系统设置")
    public String toXiTongGunLi(){
        return "admin/系统设置";
    }
    @GetMapping("admin/index")
    public String toIndex(){
        return "admin/index";
    }


    //登录方法
    @RequestMapping(value = "/admin", method = RequestMethod.GET)
    public String toDenglu(String username, String password, HttpSession session) {
        String a = null;
System.out.println("ssssssssssss");
        List<User> userList = userService.getAllUser();
        for (User user : userList) {
            //比较密码与登录名一致就登陆
//
            if ((user.getUsername().equals(username) )&&(user.getUserpassword().equals(password))) {

               session.setAttribute("sessionUser",user);
               System.out.println("sssdw");

                System.err.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + user.getUsername());
                //判断权限
                switch (user.getJurisdictionid()) {
                    case 1:
//                       toguanliyuan();

                        a="/admin/index";
                        break;
                    case 2:
                        System.out.println("sswdwdeewfw");
                        a = "/pc/登陆后";
                        break;


                }


            }else {
                System.out.println("hhhhh");
                a="pc/登陆后";
                break;
            }
//            System.out.println((user.getUsername().equals(username) )&&(user.getUserpassword().equals(password)));
            break;
        }

      return a;

    }
    //注册部分
    @RequestMapping("/zhuce.do")
    @ResponseBody
    public String zhuCe( User user){
        System.out.println("注册部分");
        System.out.println(user.getUsersex());

        return "0";
      
    }


}






